﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbConfigurationTest and is intended
    ///     to contain all TmdbConfigurationTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbConfigurationTest
    {
        /// <summary>
        ///     A test for TmdbConfiguration Constructor
        /// </summary>
        [TestMethod]
        public void TmdbConfigurationConstructorTest()
        {
            var target = new TmdbConfiguration();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for ChangeKeys
        /// </summary>
        [TestMethod]
        public void ChangeKeysTest()
        {
            var target = new TmdbConfiguration();
            var expected = new List<string>();
            target.ChangeKeys = expected;
            var actual = target.ChangeKeys;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for ImageConfiguration
        /// </summary>
        [TestMethod]
        public void ImageConfigurationTest()
        {
            var target = new TmdbConfiguration();
            var expected = new TmdbImageConfiguration();
            target.ImageConfiguration = expected;
            var actual = target.ImageConfiguration;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\configuration.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbConfiguration();
            var jsonContent = File.ReadAllText( "configuration.json.txt" );
            var actual = await target.DeserializeJson<TmdbConfiguration>( jsonContent );

            Assert.AreEqual( 30, actual.ChangeKeys.Count );
            Assert.AreEqual( "http://d3gtl9l2a4fn1j.cloudfront.net/t/p/", actual.ImageConfiguration.BaseUrl );
            Assert.AreEqual( "https://d3gtl9l2a4fn1j.cloudfront.net/t/p/", actual.ImageConfiguration.SecureBaseUrl );
            Assert.AreEqual( 6, actual.ImageConfiguration.PosterSizes.Count );
            Assert.AreEqual( 4, actual.ImageConfiguration.BackdropSizes.Count );
            Assert.AreEqual( 4, actual.ImageConfiguration.ProfileSizes.Count );
            Assert.AreEqual( 7, actual.ImageConfiguration.LogoSizes.Count );
        }
    }
}